package com.ynkj.teleprompter.db;

import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;


import java.util.ArrayList;

public class TeleprompterService {

    private MySQLite dbHelper;
    public TeleprompterService(Context context){
        dbHelper=new MySQLite(context);
    }

    /**
     * 新增收货地址
     * @return
     */
    public boolean InsertAddress(String content){
        SQLiteDatabase sdb=dbHelper.getReadableDatabase();
        String sql="insert into dataContent(teleprompter) values(?)";
        Object obj[]={content};
        sdb.execSQL(sql, obj);
        return true;
    }

    /**
     * 查询所有题词
     * @return
     */
    public ArrayList<String> dbQueryAll() {
        ArrayList<String> ArrayList = new ArrayList<String>();
        SQLiteDatabase sqliteDatabase = dbHelper.getWritableDatabase();
        String sql = "select * from dataContent";
        Cursor cursor = sqliteDatabase.rawQuery(sql, new String[]{});
        // 游标从头读到尾
        for (cursor.moveToFirst(); !(cursor.isAfterLast()); cursor.moveToNext()) {
            String teleprompter=cursor.getString(cursor.getColumnIndex("teleprompter"));
            ArrayList.add(teleprompter);
        }
        sqliteDatabase.close();
        return ArrayList;
    }

//    /**
//     *修改
//     * @return
//     */
//    public boolean updateAddress(Address address){
//        SQLiteDatabase db=dbHelper.getReadableDatabase();
//        ContentValues values = new ContentValues();
//        values.put("name", address.getName());
//        values.put("sex", address.getSex());
//        values.put("phone", address.getPhone());
//        values.put("address", address.getAddress());
//        values.put("addressDeatile", address.getAddressDeatile());
//        db.update("address", values, "id=?", new String[]{address.getId()+""});
//        db.close();
//        return true;
//    }
//
//    /**
//     * 删除
//     */
//    public void deleteAddress(int id){
//        SQLiteDatabase db=dbHelper.getReadableDatabase();
//        db.delete("address", "id=?", new String[]{Integer.toString(id)});
//    }

}
